{extend name="common:base" /}

{block name="title"}登陆 - 天佑二手货{/block}
{block name="page"}auth{/block}

{block name="header"}
<header>
    <div class="am-g">
        <h1>天佑二手货</h1>
        <p>TianYou Secondary Market
            <br/>交大人自己的二手市场！</p>
    </div>
    <hr />
</header>
{/block}

{block name="main"}
<div class="am-g am-g-fixed">
    <div class="am-u-sm-6 am-u-sm-centered">
        <h3>登录</h3>
        <hr>
        <div class="am-btn-group">
            <a href="#" class="am-btn am-btn-secondary am-btn-sm"><i class="am-icon-github am-icon-sm"></i> 天佑互联</a>
            <a href="#" class="am-btn am-btn-success am-btn-sm"><i class="am-icon-google-plus-square am-icon-sm"></i> 重庆交通大学 互联登陆</a>
        </div>
        <br>
        <br>
        <form class="am-form">
            <label for="email">邮箱:</label>
            <input type="email" name="email" id="email" value="{:cookie('email')}">
            <br>
            <label for="password">密码:</label>
            <input type="password" name="password" id="password" value="">
            <br>
            <div class="am-form-group am-form-icon am-form-feedback am-g-collapse am-cf">
                <label for="captcha" class="am-u-sm-3 am-form-label">
                    <div id="captcha-img" title="刷新验证码"><img src="{:captcha_src()}" alt="captcha" /></div>
                </label>
                <div class="am-u-sm-9">
                    <input type="text" name="captcha" id="captcha" class="am-form-field" placeholder="请输入验证码">
                    <!-- <span class="am-icon-warning"></span> -->
                </div>
            </div>
            <label for="remember-me" class="am-checkbox">
                <input id="remember-me" name="remember_me" value="1" data-am-ucheck type="checkbox"> 一个月内为我自动登陆
            </label>
            <br />
            <div class="am-cf">
                <input type="submit" name="" value="登 录" class="am-btn am-btn-primary am-btn-sm am-fl">
                <a class="am-btn am-btn-default am-btn-sm am-fr am-margin-right" href="{:url('auth/forget_password')}">忘记密码 ^_^? </a>
                <a class="am-btn am-btn-default am-btn-sm am-fr am-margin-right" href="{:url('auth/register')}">注册</a>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="js"}
<script type="text/javascript">
    $('.am-form').submit(function(event) {
        event.preventDefault();
        $.ajax({
            url: "{:url('auth/login')}",
            type: 'POST',
            data: $('.am-form').serialize(),
            success: function(data) {
                console.log(data);
                $alert = $('#am-alert');
                $alert.find('.content').text(data.msg);
                $alert.modal('open');
                if(data.code) {
                    setTimeout(function() {
                        location.href = data.url;
                    }, data.wait * 1000);
                } else {
                    $('#captcha-img').click();
                }
            }
        })
    });

</script>
{/block}
